//Created by Action Script Viewer - http://www.buraks.com/asv
package com.mui.serialization.json {
	
	public class JSON {
		
		public static function deserialize(_arg1:String):*{
			var at:Number;
			var ch:String;
			var _isDigit:Function;
			var _isHexDigit:Function;
			var _white:Function;
			var _string:Function;
			var _next:Function;
			var _array:Function;
			var _object:Function;
			var _number:Function;
			var _word:Function;
			var _value:Function;
			var _error:Function;
			var source:* = _arg1;
			source = new String(source);
			at = 0;
			ch = " ";
			_isDigit = function (_arg1:String):*{
				return (((("0" <= _arg1)) && ((_arg1 <= "9"))));
			};
			_isHexDigit = function (_arg1:String):*{
				return (((((_isDigit(_arg1)) || (((("A" <= _arg1)) && ((_arg1 <= "F")))))) || (((("a" <= _arg1)) && ((_arg1 <= "f"))))));
			};
			_error = function (_arg1:String):void{
				throw (new Error(_arg1, (at - 1)));
			};
			_next = function ():*{
				ch = source.charAt(at);
				at = (at + 1);
				return (ch);
			};
			_white = function ():void{
				while (ch) {
					if (ch <= " "){
						_next();
					} else {
						if (ch == "/"){
							switch (_next()){
								case "/":
									do  {
									} while (((((_next()) && (!((ch == "\n"))))) && (!((ch == "\r")))));
									break;
								case "*":
									_next();
									while (true) {
										if (ch){
											if (ch == "*"){
												if (_next() == "/"){
													_next();
													break;
												};
											} else {
												_next();
											};
										} else {
											_error("Unterminated Comment");
										};
									};
									break;
								default:
									_error("Syntax Error");
							};
						} else {
							break;
						};
					};
				};
			};
			_string = function ():*{
				var _local3:*;
				var _local4:*;
				var _local1:* = "";
				var _local2:* = "";
				var _local5:Boolean;
				if (ch == "\""){
					while (_next()) {
						if (ch == "\""){
							_next();
							return (_local2);
						};
						if (ch == "\\"){
							switch (_next()){
								case "b":
									_local2 = (_local2 + "\b");
									break;
								case "f":
									_local2 = (_local2 + "\f");
									break;
								case "n":
									_local2 = (_local2 + "\n");
									break;
								case "r":
									_local2 = (_local2 + "\r");
									break;
								case "t":
									_local2 = (_local2 + "\t");
									break;
								case "u":
									_local4 = 0;
									_local1 = 0;
									while (_local1 < 4) {
										_local3 = parseInt(_next(), 16);
										if (!isFinite(_local3)){
											_local5 = true;
											break;
										};
										_local4 = ((_local4 * 16) + _local3);
										_local1 = (_local1 + 1);
									};
									if (_local5){
										_local5 = false;
										break;
									};
									_local2 = (_local2 + String.fromCharCode(_local4));
									break;
								default:
									_local2 = (_local2 + ch);
							};
						} else {
							_local2 = (_local2 + ch);
						};
					};
				};
				_error("Bad String");
				return (null);
			};
			_array = function ():*{
				var _local1:Array = [];
				if (ch == "["){
					_next();
					_white();
					if (ch == "]"){
						_next();
						return (_local1);
					};
					while (ch) {
						_local1.push(_value());
						_white();
						if (ch == "]"){
							_next();
							return (_local1);
						};
						if (ch != ","){
							break;
						};
						_next();
						_white();
					};
				};
				_error("Bad Array");
				return (null);
			};
			_object = function ():*{
				var _local1:* = {};
				var _local2:* = {};
				if (ch == "{"){
					_next();
					_white();
					if (ch == "}"){
						_next();
						return (_local2);
					};
					while (ch) {
						_local1 = _string();
						_white();
						if (ch != ":"){
							break;
						};
						_next();
						_local2[_local1] = _value();
						_white();
						if (ch == "}"){
							_next();
							return (_local2);
						};
						if (ch != ","){
							break;
						};
						_next();
						_white();
					};
				};
				_error("Bad Object");
			};
			_number = function ():*{
				var _local2:*;
				var _local1:* = "";
				var _local3:* = "";
				var _local4:* = "";
				if (ch == "-"){
					_local1 = "-";
					_local4 = _local1;
					_next();
				};
				if (ch == "0"){
					_next();
					if ((((ch == "x")) || ((ch == "X")))){
						_next();
						while (_isHexDigit(ch)) {
							_local3 = (_local3 + ch);
							_next();
						};
						if (_local3 == ""){
							_error("mal formed Hexadecimal");
						} else {
							return (Number(((_local4 + "0x") + _local3)));
						};
					} else {
						_local1 = (_local1 + "0");
					};
				};
				while (_isDigit(ch)) {
					_local1 = (_local1 + ch);
					_next();
				};
				if (ch == "."){
					_local1 = (_local1 + ".");
					while (((((_next()) && ((ch >= "0")))) && ((ch <= "9")))) {
						_local1 = (_local1 + ch);
					};
				};
				_local2 = (1 * _local1);
				if (!isFinite(_local2)){
					_error("Bad Number");
				} else {
					return (_local2);
				};
				return (NaN);
			};
			_word = function ():*{
				switch (ch){
					case "t":
						if ((((((_next() == "r")) && ((_next() == "u")))) && ((_next() == "e")))){
							_next();
							return (true);
						};
						break;
					case "f":
						if ((((((((_next() == "a")) && ((_next() == "l")))) && ((_next() == "s")))) && ((_next() == "e")))){
							_next();
							return (false);
						};
						break;
					case "n":
						if ((((((_next() == "u")) && ((_next() == "l")))) && ((_next() == "l")))){
							_next();
							return (null);
						};
						break;
				};
				_error("Syntax Error");
				return (null);
			};
			_value = function ():*{
				_white();
				switch (ch){
					case "{":
						return (_object());
					case "[":
						return (_array());
					case "\"":
						return (_string());
					case "-":
						return (_number());
					default:
						return (((((ch >= "0")) && ((ch <= "9")))) ? _number() : _word());
				};
			};
			return (_value());
		}
		public static function serialize(_arg1:*):String{
			var _local2:String;
			var _local3:Number;
			var _local4:Number;
			var _local6:*;
			var _local7:String;
			var _local8:Number;
			var _local5:* = "";
			switch (typeof(_arg1)){
				case "object":
					if (_arg1){
						if ((_arg1 is Array)){
							_local4 = _arg1.length;
							_local3 = 0;
							while (_local3 < _local4) {
								_local6 = serialize(_arg1[_local3]);
								if (_local5){
									_local5 = (_local5 + ",");
								};
								_local5 = (_local5 + _local6);
								_local3++;
							};
							return ((("[" + _local5) + "]"));
						} else {
							if (typeof(_arg1.toString) != "undefined"){
								for (_local7 in _arg1) {
									_local6 = _arg1[_local7];
									if (((!((typeof(_local6) == "undefined"))) && (!((typeof(_local6) == "function"))))){
										_local6 = serialize(_local6);
										if (_local5){
											_local5 = (_local5 + ",");
										};
										_local5 = (_local5 + ((serialize(_local7) + ":") + _local6));
									};
								};
								return ((("{" + _local5) + "}"));
							};
						};
					};
					return ("null");
				case "number":
					return ((isFinite(_arg1)) ? String(_arg1) : "null");
				case "string":
					_local4 = _arg1.length;
					_local5 = "\"";
					_local3 = 0;
					while (_local3 < _local4) {
						_local2 = _arg1.charAt(_local3);
						if (_local2 >= " "){
							if ((((_local2 == "\\")) || ((_local2 == "\"")))){
								_local5 = (_local5 + "\\");
							};
							_local5 = (_local5 + _local2);
						} else {
							switch (_local2){
								case "\b":
									_local5 = (_local5 + "\\b");
									break;
								case "\f":
									_local5 = (_local5 + "\\f");
									break;
								case "\n":
									_local5 = (_local5 + "\\n");
									break;
								case "\r":
									_local5 = (_local5 + "\\r");
									break;
								case "\t":
									_local5 = (_local5 + "\\t");
									break;
								default:
									_local8 = _local2.charCodeAt();
									_local5 = (_local5 + (("\\u00" + Math.floor((_local8 / 16)).toString(16)) + (_local8 % 16).toString(16)));
							};
						};
						_local3 = (_local3 + 1);
					};
					return ((_local5 + "\""));
				case "boolean":
					return (String(_arg1));
				default:
					return ("null");
			};
		}
		
	}
}//package com.mui.serialization.json 
